﻿
namespace YasharEl.Infrastructure
{
    public static class StringUtil
    {
        public static int CountOccurrencesOf(this string input, string occurrencesToMatch)
        {
            if (string.IsNullOrEmpty(input))
                return 0;
            if (string.IsNullOrEmpty(occurrencesToMatch))
                return 0;

            int count = 0;
            int startIndex = 0;
            int foundIndex = 0;
            while ((foundIndex = input.IndexOf(occurrencesToMatch, startIndex)) != -1)
            {
                count++;
                startIndex = foundIndex + occurrencesToMatch.Length;
            }
            return count;
        }
    }
}
